package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.IntegralAccount;
import com.ysqcould.allocation.domain.vo.IntegralVo;
import com.ysqcould.allocation.service.IIntegralAccountService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 积分记录--积分账号Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/allocation/account")
public class IntegralAccountController extends BaseController
{
    @Autowired
    private IIntegralAccountService integralAccountService;

    /**
     * 查询积分记录--积分账号列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(IntegralAccount integralAccount)
    {
        startPage();
        List<IntegralVo> list = integralAccountService.selectIntegralAccountList(integralAccount);
        return getDataTable(list);
    }

    /**
     * 导出积分记录--积分账号列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:account:export')")
    @Log(title = "积分记录--积分账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntegralAccount integralAccount)
    {
        List<IntegralVo> list = integralAccountService.selectIntegralAccountList(integralAccount);
        ExcelUtil<IntegralVo> util = new ExcelUtil<IntegralVo>(IntegralVo.class);
        util.exportExcel(response, list, "积分记录--积分账号数据");
    }

    /**
     * 获取积分记录--积分账号详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:account:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(integralAccountService.selectIntegralAccountById(id));
    }

    /**
     * 新增积分记录--积分账号
     */
    @PreAuthorize("@ss.hasPermi('allocation:account:add')")
    @Log(title = "积分记录--积分账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntegralAccount integralAccount)
    {
        return toAjax(

                integralAccountService.insertIntegralAccount(integralAccount));
    }

    /**
     * 修改积分记录--积分账号
     */
    @PreAuthorize("@ss.hasPermi('allocation:account:edit')")
    @Log(title = "积分记录--积分账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralAccount integralAccount)
    {
        return toAjax(
                integralAccountService.updateIntegralAccount(integralAccount));
    }

    /**
     * 删除积分记录--积分账号
     */
    @PreAuthorize("@ss.hasPermi('allocation:account:remove')")
    @Log(title = "积分记录--积分账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integralAccountService.deleteIntegralAccountByIds(ids));
    }
}
